package com.zmn.oms.business.impl.third;

import com.zmn.oms.business.interfaces.third.ZhimiExtendOrderService;
import com.zmn.oms.model.entity.third.ZhimiExtendOrder;
import com.zmn.oms.persistence.interfaces.third.ZhimiExtendOrderDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @author: lhl
 * @create: 2020-04-28 18:51
 **/
@Service
public class zhimiExtendOrderServiceImpl implements ZhimiExtendOrderService {

    @Resource
    private ZhimiExtendOrderDao zhimiExtendOrderDao;

    @Override
    public ZhimiExtendOrder findByOrderId(Long orderId, boolean containsExtendData) {
        if (!Optional.ofNullable(orderId).isPresent()) {
            return null;
        }

        if (containsExtendData) {
            return zhimiExtendOrderDao.findByOrderId(orderId);
        }
        else {
            return zhimiExtendOrderDao.findMiniByOrderId(orderId);
        }
    }

    /**
     * 查询指定时间录入的订单信息
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<ZhimiExtendOrder> listByCreateTime(Date startTime, Date endTime) {
        return zhimiExtendOrderDao.listByCreateTime(startTime, endTime);
    }

    /**
     * 获取申请了配件需要查询配件邮寄信息的订单
     * @param startTime
     * @return
     */
    @Override
    public List<ZhimiExtendOrder> listNoExpressOrders(Date startTime) {
        return zhimiExtendOrderDao.listNoExpressOrders(startTime);
    }

    @Override
    public void save(ZhimiExtendOrder zhimiExtendOrder) {
        zhimiExtendOrderDao.save(zhimiExtendOrder);
    }

    @Override
    public void updateByKey(ZhimiExtendOrder zhimiExtendOrder) {
        zhimiExtendOrderDao.updateByKey(zhimiExtendOrder);
    }

    @Override
    public void updateServiceTypeByKey(ZhimiExtendOrder zhimiExtendOrder) {
        zhimiExtendOrderDao.updateServiceTypeByKey(zhimiExtendOrder);
    }
}
